<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 小西瓜 <751707632@qq.com.com>
// +----------------------------------------------------------------------
namespace app\api\model;

use app\admin\model\RouteModel;
use think\Model;
use think\Db;
use tree\Tree;

class ImsAddressModel extends Model
{
    /**
     * 获取地址列表
     * @params array $where  查询条件
     * @params atring $field 查询字段
     * @params string $order 按字段排序
     * @return array
     */
    public function lists($where=[], $field='*', $order='id desc')
    {
    	$lists = $this->where($where)->field($field)->order($order)->select()->toArray();
        $data = array();
    	foreach ( $lists as $key => $val ) {
    		if ( !empty($val['province_id']) ) {
    			$province = Db::name('ims_regions')->where('region_id',$val['province_id'])->value('region_name');
    		}
    		if ( !empty($val['city_id']) ) {
    			$city = Db::name('ims_regions')->where('region_id',$val['city_id'])->value('region_name');
    		}
    		if ( !empty($val['area_id']) ) {
    			$area = Db::name('ims_regions')->where('region_id',$val['area_id'])->value('region_name');
    		}
            $data[$key]['address_id'] = $val['id'];
    		$data[$key]['area'] = $province.$city.$area.' '.$val['address'];
            $data[$key]['is_default'] = $val['is_default'];
    	}

    	return $data;
    }
}